/*
 * MODULE  NAME  :
 * PROGRAM NAME  : main.h
 * AUTHOR        : hotmocha(hotmocha@126.com)
 * CREATE  DATE  : 2015-10-20 14:56:34
 * PROGRAM DESC  :
 *
 * HISTORY       :
 *
 */
#ifndef _H_SERVER_H_
#define _H_SERVER_H_

#include "constants.h"
#include "tknetbusi.h"
#include "memberlist.dsc.h"

struct config {
	char logpath[FILEPATHMAXLEN];
	int serverport;
	int maxconnecting;
	char tkhistory[FILEPATHMAXLEN];
	char recvfilepath[FILEPATHMAXLEN];
};

struct session {
	char clientip[IPV4LEN];
	int clientport;
	char sendbuffer[10][MSGMAXLEN];		/* max store 5 messages */
	char recvbuffer[MSGMAXLEN];		/* client use sync send */
};

struct serverenv {
	struct epoll_env *epoll_env;
	int listenfd;

	struct config *conf;

	int connectnum;
	struct list_head clients_list;  /* put struct tk_connect */
	memberlist member_list;   
};

int add_client_conn(struct tk_connect *conn);
int del_client_conn(struct tk_connect *conn);
FILE* create_recv_file(char *filename);

/**** REDIS key ****/
#define TK_MEMBER_LIST 		"MEMBER_LIST"
#define TK_MSG_ID		"MSG_ID"
#define TK_HS_MSG		"HS_MSG"
#define TK_MSG_GROUP_BY_CLI	"HS_MSG_BY_CLIENT"

#endif
